<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-04 16:21:31
 * @LastEditTime: 2023-07-04 14:37:23
 * @LastEditors: 孙开源 && sunkaiyuan@namenode.cn
 * @Description: 
 */

namespace App\Http\Controllers\System;

use App\Http\Controllers\Controller;
use App\Http\Services\System\TemporaryTokenService;
use Illuminate\Http\Request;
use App\Http\Services\System\UserService;

class UserController extends Controller
    {
    //
    public $temporary;
    public function boot(UserService $user_services, TemporaryTokenService $temporaryToken)
        {
        $this->service   = $user_services;
        $this->temporary = $temporaryToken;
        }
    public function DingTalkAuth()
        {
        return $this->service->DingTalkAuth();
        }
    /**
     * @OA\Post(
     *   tags={"用户登陆"},
     *   path="/token",
     *   summary="用户登陆，获取用户token",
     *     @OA\RequestBody(
     *     required=true,
     *     request="loginForm",
     *     description="登录",
     *       @OA\MediaType(
     *          mediaType="application/x-www-form-urlencoded",
     *           @OA\Schema(
     *             required={"username","password"},
     *             @OA\Property(property="username",title="账户名",type="string"),
     *             @OA\Property(property="password",title="密码",type="string")
     *          )
     *       )
     *    ),
     *     @OA\Response(
     *         response="200",
     *         description="请求成功",
     *           @OA\JsonContent(
     *             @OA\Property(property="code",title="响应代码",type="integer",example=200),
     *             @OA\Property(property="message",title="错误信息",type="string",example="ok"),
     *             @OA\Property(
     *                      property="data",
     *                      title="响应数据",
     *                      @OA\Property(property="api_token",title="令牌信息",type="string",example="ok"),
     *                      @OA\Property(
     *                          property="userinfo",
     *                          title="用户信息",
     *                          ref="#/components/schemas/UserProperties"
     *                   )
     *
     *              )
     *       )
     *     ),
     *  )
     */

    public function login(Request $request)
        {
        return $this->service->login($request);
        }
    /**
     * @OA\Post(
     *   tags={"用户登陆"},
     *   path="/logout",
     *   summary="用户退出",
     *     @OA\Response(
     *         response="200",
     *         description="请求成功",
     *           @OA\JsonContent(
     *             @OA\Property(property="code",title="响应代码",type="integer",example=200),
     *             @OA\Property(property="message",title="错误信息",type="string",example="ok"),
     *             @OA\Property(
     *                      property="data",
     *                      title="错误信息",type="string",example="ok"
     *              )
     *       )
     *     ),
     *  )
     */
    public function logout(Request $request)
        {
        return $this->service->login($request);
        }

    protected function reSetPassWord()
        {
        return $this->service->reSetPassWord();
        }
    public function list()
        {
        return $this->service->list();
        }

    public function save(Request $request)
        {
        return $this->service->save($request);
        }

    public function delete(Request $request)
        {
        return $this->service->delete($request);
        }
    public function menu(Request $request)
        {
        return $this->service->menu($request);
        }
    /**
     * 短信验证登录
     */
    protected function getPhoneCode()
        {
        return $this->service->getPhoneCode();
        }
    public function createToken()
        {
        return $this->temporary->create();
        }

    public function userTokenList()
        {
        return $this->temporary->userList();
        }
    public function allowlogin()
        {
        return $this->service->allowlogin(0);
        }
    public function noallowlogin()
        {
        return $this->service->allowlogin(1);
        }
    protected function userTokenDelete()
        {
        return $this->temporary->userTokenDelete();
        }
    }